package com.dtw.ditouwang.ui.mine

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.dtw.ditouwang.R
import com.dtw.ditouwang.beans.HelpBean
import com.dtw.ditouwang.models.WebApi
import com.dtw.ditouwang.ui.OnItemClickListener
import kotlinx.android.synthetic.main.item_help.view.*

class HelpAdapter(var subDataBean: ArrayList<HelpBean.DataBean.SubDataBean>): RecyclerView.Adapter<HelpAdapter.Holder>() {
    var onItemClickListener:OnItemClickListener?=null


    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): Holder {
        return Holder(LayoutInflater.from(p0.context).inflate(R.layout.item_help,p0,false))
    }

    override fun getItemCount(): Int {
        return subDataBean.size
    }

    override fun onBindViewHolder(p0: Holder, p1: Int) {
        if(subDataBean[p1].is_type==1) {
            Glide.with(p0.itemView.image_view).load(WebApi.BaseUrl +subDataBean[p1].img).into(p0.itemView.image_view)
        }
        p0.itemView.text_title.text=subDataBean[p1].title
    }

    inner class Holder(itemView:View): RecyclerView.ViewHolder(itemView) {
        init {
            itemView.setOnClickListener({
                onItemClickListener?.onItemClick(subDataBean[adapterPosition].is_type,adapterPosition,subDataBean[adapterPosition].id)
            })
        }
    }
}